package com.server.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.server.service.IMngRoleService;
@Service("MngRoleService")
public class MngRoleService implements IMngRoleService{
	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Autowired
	private CommonDataService commonDataService;
	
	@Override
	public List<Map<String, Object>> roleList() {
		String sql = "select * from education.admin_role where valid=1";
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		list = jdbcTemplate.queryForList(sql);
		return list;
	}

	@Override
	public Boolean addRole(Map<String, Object> inputMap,String operator) {
		Boolean isSuccess = commonDataService.add(operator, "education.admin_role", inputMap);
		return isSuccess;
	}

	@Override
	public Boolean updateRole(Map<String, Object> inputMap, String field,
			String value,String operator) {
		 Boolean isSuccess = commonDataService.update(operator, "education.admin_role", field, value, inputMap);
		return isSuccess;
	}

	@Override
	public Boolean deletRole(String field, String value) {
		Boolean isSuccess = commonDataService.delete("education.admin_role", field, value);
		return isSuccess;
	}

	@Override
	public Map<String, Object> getRoleById(int id) {
		Map<String, Object> roleMap = new HashMap<String, Object>();
		String sql = "select * from education.admin_role where id=%d";
		List<Map<String, Object>> list = jdbcTemplate.queryForList(String.format(sql, id));
		if(list.size()>0){
			roleMap = list.get(0);
		}
		return roleMap;
	}
	

}
